<!DOCTYPE html>
<html lang="en">

<head>
  <meta charset="UTF-8">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>Document</title>
  <script src="../vue.js"></script>
</head>

<body>
  <div id="app">

    <button-counter :num="initCount"></button-counter>
    <!-- <counter2001 num="5"></counter2001>
    <counter2001 num="10"></counter2001> -->

  </div>


  <script>

    //全局组件
    Vue.component('ButtonCounter', {
      props: ['num'],
      created() {
        console.log(this.num)
        this.count = this.num;
      },
      data() {
        return {
          count: this.num
        }
      },
      template: `
      <div>
      <h1>{{count}}-父组件传过来：{{this.num}}</h1>
      <button @click="increment">增加</button>
      <hr/>
    </div>
`,
      methods: {
        increment() {
          this.count = parseInt(this.count) + 1;
        }
      }
    })

    var vm = new Vue({
      el: '#app',
      component: {

      },
      data: {
        initCount: 5
      }
    })


  </script>


</body>

</html>